invalid type argument of `unary *'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nsbcnjsbc
    New Member
    • Jun 2013
    • 1

    invalid type argument of `unary *'

    What's wrong?here's the code




    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #define pi  3.141592;
    
    int main(void)
    {
    
    float radium,diameter,perimeter,area;
     printf("please input radium:");
     scanf("%f",&radium);
     diameter =2.0*radium;
     perimeter =2.0*radium*pi;
     area=radium*pi*radium;
     printf("the diameter:%f\n the perimeter:%f\nthe area%f\n",diameter,perimeter,area);
      
     
      
      system("PAUSE");	
      return 0;
    }
    Last edited by Rabbit; Jun 28 '13, 04:35 AM. Reason: Please use code tags when posting code.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    The problem is not with the * operator, it can be chained as it is at line 13 if all the operands are variables or constants.

    The problem all the operands are not variables or constants because at line 3 you have put a semi-colon at the end of your definition of pi which means that after preprocessing line 13 looks like this
    Code:
    area=radium*3.141592;*radium;
    With the extra ; the second * forms part of a second expression and it only has 1 operand so it is treated as the unary dereference operator, this operator operates on pointers and radium is a float so you get the error

    [I]error: invalid type argument of unary '*' (have 'float')/I]

    Remove the ; from line 3

    Comment

    Working...